class Solution:
    def lengthOfLongestSubstring(self, s: str) -> int:
        cnt = Counter()
        ans = 0
        left = 0

        for  right,letter in enumerate(s):
            cnt[letter] += 1
            while cnt[letter] > 1:
                cnt[s[left]] -= 1
                left+=1
            ans = max(ans,right-left+1)
        return ans


